package controllers

import (
	"weiboxs.com/new_h_glasses/enums"
	"weiboxs.com/new_h_glasses/services"
)

type SmsController struct {
	BaseController
}

//Prepare 参考beego官方文档说明
func (c *SmsController) Prepare() {
	//先执行
	c.BaseController.Prepare()
}

//弹窗发送
func (c *SmsController) SendDialog() {

	if c.Ctx.Input.IsPost() { //开始发送

		mobile := c.GetString("mobile")
		message := c.GetString("message")
		if  len(mobile) <= 0 || len(message) <= 0 {
			c.jsonResult(enums.JRCodeFailed, "请填写手机号及短信内容", "")
			return
		}

		argv := services.SmsArgv{}
		argv.Typeid = 2
		argv.DepartmentId = c.curUser.DepartmentId
		argv.CreatedBy = c.curUser.RealName
		argv.Mobile = mobile
		argv.Content = message

		sms, _ := services.NewSms()
		if err := sms.Send(&argv); err != nil {
			c.jsonResult(enums.JRCodeFailed, err.Error(), "")
		}

		c.jsonResult(enums.JRCodeSucc, "发送成功", "")

	} else {
		c.display("", "sms/senddialog_footerjs.html", "shared/layout_dialog.html")
	}
}
